﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>VIC常用工具类</title>
		<link href="//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.css" rel="stylesheet">
		<link href="https://www.zybuluo.com/static/img/favicon.png" type="image/x-icon" rel="icon">
		<link href="https://www.zybuluo.com/static/assets/1bc053c8.base.lib.min.css" rel="stylesheet" media="screen">
		<link id="prettify-style" href="https://www.zybuluo.com/static/editor/libs/google-code-prettify/prettify-cmd.css" type="text/css" rel="stylesheet">
		<link href="https://www.zybuluo.com/static/assets/mdeditor/45c7d56d.layout.min.css" rel="stylesheet" media="screen">

	</head>

	<body>
		<div class="container">
			<div class="row">
				<div class="col-md12">
					<!--********************************-->

					<div id="wmd-preview" class="wmd-preview">
						<div class="md-section-divider"></div>
						<p data-anchor-id="sia7">
							<div class="toc">
								<ul>
									<li>
										<a href="#vic常用工具类">VIC常用工具类</a>
										<ul>
											<li>
												<a href="#1-json工具类">1. JSON工具类</a>
											</li>
											<li>
												<a href="#2-读取src下配置文件工具类">2. 读取src下配置文件工具类</a>
												<ul>
													<li>
														<a href="#3-正则工具类">3. 正则工具类</a>
													</li>
												</ul>
											</li>
											<li>
												<a href="#4-ioutils">4. IOUtils</a>
											</li>
										</ul>
									</li>
								</ul>
							</div>
						</p>
						<div class="md-section-divider"></div>
						<h1 data-anchor-id="hk0m" id="vic常用工具类">VIC常用工具类</h1>
						<p data-anchor-id="9vsk"><code>工具类</code> <code>java</code></p>
						<div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="yyhc" style=""><ol class="linenums"><li class="L0"><code><span class="pln"> </span><span class="pun">一些项目中常用的</span><span class="pln">java</span><span class="pun">工具类</span></code></li></ol></pre>
						<hr>
						<div class="md-section-divider"></div>
						<h2 data-anchor-id="2fv2" id="1-json工具类">1. JSON工具类</h2>
						<div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="46q9" style=""><ol class="linenums"><li class="L0"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">IOException</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">codehaus</span><span class="pun">.</span><span class="pln">jackson</span><span class="pun">.</span><span class="typ">JsonGenerationException</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">codehaus</span><span class="pun">.</span><span class="pln">jackson</span><span class="pun">.</span><span class="typ">JsonParseException</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">codehaus</span><span class="pun">.</span><span class="pln">jackson</span><span class="pun">.</span><span class="pln">map</span><span class="pun">.</span><span class="typ">JsonMappingException</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">codehaus</span><span class="pun">.</span><span class="pln">jackson</span><span class="pun">.</span><span class="pln">map</span><span class="pun">.</span><span class="typ">ObjectMapper</span><span class="pun">;</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="com">/**</span></code></li><li class="L7"><code class="language-java"><span class="com"> * JSON工具类</span></code></li><li class="L8"><code class="language-java"><span class="com"> * @author VIC</span></code></li><li class="L9"><code class="language-java"><span class="com"> *</span></code></li><li class="L0"><code class="language-java"><span class="com"> */</span></code></li><li class="L1"><code class="language-java"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">JsonUtil</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">ObjectMapper</span><span class="pln"> mapper</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="kwd">static</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L4"><code class="language-java"><span class="pln">        mapper </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ObjectMapper</span><span class="pun">();</span></code></li><li class="L5"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L7"><code class="language-java"><span class="com">     * 1 对象转json</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param obj</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L0"><code class="language-java"><span class="com">     */</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> pareseToJson</span><span class="pun">(</span><span class="typ">Object</span><span class="pln"> obj</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">JsonGenerationException</span><span class="pun">,</span><span class="pln"> </span><span class="typ">JsonMappingException</span><span class="pun">,</span><span class="pln"> </span><span class="typ">IOException</span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> mapper</span><span class="pun">.</span><span class="pln">writeValueAsString</span><span class="pun">(</span><span class="pln">obj</span><span class="pun">)</span><span class="pln"> </span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"></code></li><li class="L5"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L6"><code class="language-java"><span class="com">     * 2 json转class</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param json</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param classType</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L0"><code class="language-java"><span class="com">     */</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="pun">&lt;</span><span class="pln">T</span><span class="pun">&gt;</span><span class="pln"> T parseToClass</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> json</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Class</span><span class="pun">&lt;</span><span class="pln">T</span><span class="pun">&gt;</span><span class="pln"> classType</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">JsonParseException</span><span class="pun">,</span><span class="pln"> </span><span class="typ">JsonMappingException</span><span class="pun">,</span><span class="pln"> </span><span class="typ">IOException</span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> mapper</span><span class="pun">.</span><span class="pln">readValue</span><span class="pun">(</span><span class="pln">json</span><span class="pun">,</span><span class="pln"> classType</span><span class="pun">);</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li></ol></pre>
						<div class="md-section-divider"></div>
						<h2 data-anchor-id="75c6" id="2-读取src下配置文件工具类">2. 读取src下配置文件工具类</h2>
						<div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="3ytg" style=""><ol class="linenums"><li class="L0"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">InputStream</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">Properties</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">apache</span><span class="pun">.</span><span class="pln">commons</span><span class="pun">.</span><span class="pln">lang</span><span class="pun">.</span><span class="typ">StringUtils</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="com">/**</span></code></li><li class="L4"><code class="language-java"><span class="com"> * 读取配置文件工具类</span></code></li><li class="L5"><code class="language-java"><span class="com"> * @author VIC</span></code></li><li class="L6"><code class="language-java"><span class="com"> *</span></code></li><li class="L7"><code class="language-java"><span class="com"> */</span></code></li><li class="L8"><code class="language-java"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">PropertiesUtil</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"></code></li><li class="L0"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">Properties</span><span class="pln"> properties </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">final</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> PROP_RESOURCE </span><span class="pun">=</span><span class="pln"> </span><span class="str">"some.properties"</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">Properties</span><span class="pln"> getPara</span><span class="pun">(){</span></code></li><li class="L4"><code class="language-java"><span class="pln">        properties </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Properties</span><span class="pun">();</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">try</span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">            </span><span class="typ">InputStream</span><span class="pln"> in </span><span class="pun">=</span><span class="pln"> </span><span class="typ">PropertiesUtil</span><span class="pun">.</span><span class="kwd">class</span><span class="pun">.</span><span class="pln">getClassLoader</span><span class="pun">().</span><span class="pln">getResourceAsStream</span><span class="pun">(</span><span class="pln">PROP_RESOURCE</span><span class="pun">);</span></code></li><li class="L7"><code class="language-java"><span class="pln">            properties</span><span class="pun">.</span><span class="pln">load</span><span class="pun">(</span><span class="pln">in</span><span class="pun">);</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="kwd">catch</span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"><span class="pln">            e</span><span class="pun">.</span><span class="pln">printStackTrace</span><span class="pun">();</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> properties</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getStringByKey</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> key</span><span class="pun">){</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="kwd">null</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> properties</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">            </span><span class="typ">PropertiesUtil</span><span class="pun">.</span><span class="pln">getPara</span><span class="pun">();</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">try</span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> properties</span><span class="pun">.</span><span class="pln">getProperty</span><span class="pun">(</span><span class="pln">key</span><span class="pun">);</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="kwd">catch</span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"><span class="pln">            e</span><span class="pun">.</span><span class="pln">printStackTrace</span><span class="pun">();</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> getIntByKey</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> key </span><span class="pun">){</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="typ">String</span><span class="pln"> val </span><span class="pun">=</span><span class="pln"> getStringByKey</span><span class="pun">(</span><span class="pln">key</span><span class="pun">);</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isNotBlank</span><span class="pun">(</span><span class="pln">val</span><span class="pun">)){</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Integer</span><span class="pun">.</span><span class="pln">parseInt</span><span class="pun">(</span><span class="pln">val</span><span class="pun">);</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li></ol></pre>
						<div class="md-section-divider"></div>
						<h3 data-anchor-id="i77j" id="3-正则工具类">3. 正则工具类</h3>
						<div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="cfze" style=""><ol class="linenums"><li class="L0"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">UnsupportedEncodingException</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">net</span><span class="pun">.</span><span class="typ">URLEncoder</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">ArrayList</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">Collections</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">List</span><span class="pun">;</span></code></li><li class="L5"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="pln">regex</span><span class="pun">.</span><span class="typ">Matcher</span><span class="pun">;</span></code></li><li class="L6"><code class="language-java"><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="pln">regex</span><span class="pun">.</span><span class="typ">Pattern</span><span class="pun">;</span></code></li><li class="L7"><code class="language-java"></code></li><li class="L8"><code class="language-java"><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">apache</span><span class="pun">.</span><span class="pln">commons</span><span class="pun">.</span><span class="pln">lang</span><span class="pun">.</span><span class="typ">StringUtils</span><span class="pun">;</span></code></li><li class="L9"><code class="language-java"></code></li><li class="L0"><code class="language-java"><span class="com">/**</span></code></li><li class="L1"><code class="language-java"><span class="com"> * 正则工具类</span></code></li><li class="L2"><code class="language-java"><span class="com"> * @author Administrator</span></code></li><li class="L3"><code class="language-java"><span class="com"> *</span></code></li><li class="L4"><code class="language-java"><span class="com"> */</span></code></li><li class="L5"><code class="language-java"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">RegexUtil</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">final</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> rootUrlRegex </span><span class="pun">=</span><span class="pln"> </span><span class="str">"((http|https)://.*?/)"</span><span class="pun">;</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">final</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> currentUrlRegex </span><span class="pun">=</span><span class="pln"> </span><span class="str">"((http|https)://.*/)"</span><span class="pun">;</span></code></li><li class="L8"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">final</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> </span><span class="typ">CHRegex</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="str">"([\u4E00-\u9FA5])"</span><span class="pun">;</span></code></li><li class="L9"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L0"><code class="language-java"><span class="com">     * 1 返回字符串中匹配正则的字符串并根据分隔符拼接</span></code></li><li class="L1"><code class="language-java"><span class="com">     * @param srcStr   源字符串</span></code></li><li class="L2"><code class="language-java"><span class="com">     * @param regexStr 正则表达式 </span></code></li><li class="L3"><code class="language-java"><span class="com">     * @param splitStr  分隔符</span></code></li><li class="L4"><code class="language-java"><span class="com">     * @param n  所在正则的位置</span></code></li><li class="L5"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L6"><code class="language-java"><span class="com">     */</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getString</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> splitStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> n</span><span class="pun">){</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> n </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        splitStr </span><span class="pun">=</span><span class="pln"> splitStr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">?</span><span class="pln"> </span><span class="str">""</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> splitStr</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="com">//CASE_INSENSITIVE：当我们在匹配的时候要忽略字符大小写时 DOTALL:使用这个选项之后metacharacter .就可以包括一行的终止字符了，如果没有这个选项， 一行的终止字符，并不会考虑在字符串之内的。 使用这个选项会降低效率 </span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr </span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="typ">StringBuffer</span><span class="pln"> sb </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StringBuffer</span><span class="pun">();</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pun">(</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">()</span><span class="pln"> </span><span class="pun">){</span></code></li><li class="L7"><code class="language-java"><span class="pln">            sb</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">n</span><span class="pun">).</span><span class="pln">trim</span><span class="pun">()).</span><span class="pln">append</span><span class="pun">(</span><span class="pln">splitStr</span><span class="pun">);</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L9"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">sb</span><span class="pun">.</span><span class="pln">length</span><span class="pun">()</span><span class="pln"> </span><span class="pun">&gt;</span><span class="pln"> </span><span class="lit">0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L0"><code class="language-java"><span class="pln">            sb</span><span class="pun">.</span><span class="pln">deleteCharAt</span><span class="pun">(</span><span class="pln">sb</span><span class="pun">.</span><span class="pln">length</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> sb</span><span class="pun">.</span><span class="pln">toString</span><span class="pun">();</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L5"><code class="language-java"><span class="com">     *  2 返回字符串中匹配正则的字符串拼接</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param n</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L0"><code class="language-java"><span class="com">     */</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getString</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> n</span><span class="pun">){</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> getString</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">,</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">,</span><span class="pln"> n</span><span class="pun">);</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L5"><code class="language-java"><span class="com">     * 3 返回第一条匹配的结果</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param n</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L0"><code class="language-java"><span class="com">     */</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getFirstString</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> n</span><span class="pun">){</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> n </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr </span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pun">(</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">n</span><span class="pun">).</span><span class="pln">trim</span><span class="pun">();</span></code></li><li class="L9"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L4"><code class="language-java"><span class="com">     *  4 回字符串中匹配正则的字符串 放入list集合</span></code></li><li class="L5"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param n</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L9"><code class="language-java"><span class="com">     */</span></code></li><li class="L0"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> getList</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> n</span><span class="pun">){</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> n </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Collections</span><span class="pun">.</span><span class="pln">emptyList</span><span class="pun">();</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> list </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;&gt;();</span><span class="pln"> </span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr </span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pun">(</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">()</span><span class="pln"> </span><span class="pun">){</span></code></li><li class="L8"><code class="language-java"><span class="pln">            list</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">n</span><span class="pun">));</span></code></li><li class="L9"><code class="language-java"></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> list</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L5"><code class="language-java"><span class="com">     * 5 获取字符中匹配正则的全部数据String集合 放入list集合</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param arr 正则位置数组</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L0"><code class="language-java"><span class="com">     */</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">[]&gt;</span><span class="pln"> getList</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pun">[]</span><span class="pln"> arr</span><span class="pun">){</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="pun">(</span><span class="pln">arr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Collections</span><span class="pun">.</span><span class="pln">emptyList</span><span class="pun">();</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">int</span><span class="pln"> len </span><span class="pun">=</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln"> len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">){</span></code></li><li class="L8"><code class="language-java"><span class="pln">                </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Collections</span><span class="pun">.</span><span class="pln">emptyList</span><span class="pun">();</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">[]&gt;</span><span class="pln"> list </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;&gt;();</span><span class="pln"> </span></code></li><li class="L2"><code class="language-java"></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">            </span><span class="typ">String</span><span class="pun">[]</span><span class="pln"> ss </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">String</span><span class="pun">[</span><span class="pln">len</span><span class="pun">];</span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln">len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">                ss</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]).</span><span class="pln">trim</span><span class="pun">();</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pln">            list</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">ss</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> list</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"></code></li><li class="L5"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L6"><code class="language-java"><span class="com">     * 6 获取字符中匹配正则的全部数据String 放入list集合</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @param arr 正则位置数组</span></code></li><li class="L0"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L1"><code class="language-java"><span class="com">     */</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> getStringList</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pun">[]</span><span class="pln"> arr</span><span class="pun">){</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="pun">(</span><span class="pln">arr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L4"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Collections</span><span class="pun">.</span><span class="pln">emptyList</span><span class="pun">();</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="kwd">int</span><span class="pln"> len </span><span class="pun">=</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln"> len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">            </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">){</span></code></li><li class="L9"><code class="language-java"><span class="pln">                </span><span class="kwd">return</span><span class="pln"> </span><span class="typ">Collections</span><span class="pun">.</span><span class="pln">emptyList</span><span class="pun">();</span></code></li><li class="L0"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> list </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;&gt;();</span><span class="pln"> </span></code></li><li class="L3"><code class="language-java"></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="typ">StringBuffer</span><span class="pln"> sb </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StringBuffer</span><span class="pun">();</span></code></li><li class="L8"><code class="language-java"><span class="pln">            </span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln">len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"><span class="pln">                sb</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]).</span><span class="pln">trim</span><span class="pun">());</span></code></li><li class="L0"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">            list</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">sb</span><span class="pun">.</span><span class="pln">toString</span><span class="pun">());</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> list</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L7"><code class="language-java"><span class="com">     * 7 获取字符中匹配正则的第一条数据 String[]</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @param srcStr</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L0"><code class="language-java"><span class="com">     * @param arr 正则位置数组</span></code></li><li class="L1"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L2"><code class="language-java"><span class="com">     */</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pun">[]</span><span class="pln"> getFirstyArray</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pun">[]</span><span class="pln"> arr</span><span class="pun">){</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> </span><span class="pun">(</span><span class="pln">arr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">int</span><span class="pln"> len </span><span class="pun">=</span><span class="pln"> arr</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i </span><span class="pun">&lt;</span><span class="pln"> len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L0"><code class="language-java"><span class="pln">                </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">            </span><span class="typ">String</span><span class="pun">[]</span><span class="pln"> ss </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">String</span><span class="pun">[</span><span class="pln">len</span><span class="pun">];</span><span class="pln"> </span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i </span><span class="pun">&lt;</span><span class="pln"> len</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">                ss</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">arr</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]).</span><span class="pln">trim</span><span class="pun">();</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> ss</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L5"><code class="language-java"><span class="com">     *  8 .组装网址，网页的URL</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @param url</span></code></li><li class="L7"><code class="language-java"><span class="com">     * @param currentUrl</span></code></li><li class="L8"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L9"><code class="language-java"><span class="com">     */</span></code></li><li class="L0"><code class="language-java"><span class="pln">    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getHttpUrl</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> url</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> currentUrl</span><span class="pun">){</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="kwd">try</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">            </span><span class="com">//新增的replaceAll  转化有些地址接口中的转化地址，如： \/test\/1.html</span></code></li><li class="L3"><code class="language-java"><span class="pln">            url </span><span class="pun">=</span><span class="pln"> encodeUrlCh</span><span class="pun">(</span><span class="pln">url</span><span class="pun">).</span><span class="pln">replaceAll</span><span class="pun">(</span><span class="str">"\\\\/"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"/"</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">catch</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code class="language-java"><span class="pln">            </span><span class="com">// TODO Auto-generated catch block  </span></code></li><li class="L6"><code class="language-java"><span class="pln">            e</span><span class="pun">.</span><span class="pln">printStackTrace</span><span class="pun">();</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">url</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="str">"http"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0</span><span class="pun">){</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> url</span><span class="pun">;</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L1"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pln">  </span><span class="pun">(</span><span class="pln">url</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="str">"/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0</span><span class="pun">){</span></code></li><li class="L2"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> getFirstString</span><span class="pun">(</span><span class="pln">currentUrl</span><span class="pun">,</span><span class="pln"> rootUrlRegex</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> url</span><span class="pun">.</span><span class="pln">substring</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="pln"> </span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pln">  </span><span class="pun">(</span><span class="pln">url</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="str">"\\/"</span><span class="pun">)</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0</span><span class="pun">){</span></code></li><li class="L5"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> getFirstString</span><span class="pun">(</span><span class="pln">currentUrl</span><span class="pun">,</span><span class="pln"> rootUrlRegex</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> url</span><span class="pun">.</span><span class="pln">substring</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> getFirstString</span><span class="pun">(</span><span class="pln">currentUrl</span><span class="pun">,</span><span class="pln"> currentUrlRegex</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> url</span><span class="pun">;</span></code></li><li class="L8"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L9"><code class="language-java"></code></li><li class="L0"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L1"><code class="language-java"><span class="com">     *  9 获取和正则匹配的绝对链接地址</span></code></li><li class="L2"><code class="language-java"><span class="com">     * @param dealStr</span></code></li><li class="L3"><code class="language-java"><span class="com">     * @param regexStr</span></code></li><li class="L4"><code class="language-java"><span class="com">     * @param currentUrl</span></code></li><li class="L5"><code class="language-java"><span class="com">     * @param n</span></code></li><li class="L6"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L7"><code class="language-java"><span class="com">     */</span></code></li><li class="L8"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> getArrayList</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> srcStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> currentUrl</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> n</span><span class="pun">){</span></code></li><li class="L9"><code class="language-java"><span class="pln">        </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> reArrayList </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;();</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">srcStr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> regexStr </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> n </span><span class="pun">&lt;</span><span class="pln"> </span><span class="lit">1</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> srcStr</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">()){</span></code></li><li class="L1"><code class="language-java"><span class="pln">            </span><span class="kwd">return</span><span class="pln"> reArrayList</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="typ">Pattern</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">regexStr</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">CASE_INSENSITIVE </span><span class="pun">|</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">DOTALL</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">Matcher</span><span class="pln"> matcher </span><span class="pun">=</span><span class="pln"> pattern</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">srcStr</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">            reArrayList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">getHttpUrl</span><span class="pun">(</span><span class="pln">matcher</span><span class="pun">.</span><span class="pln">group</span><span class="pun">(</span><span class="pln">n</span><span class="pun">).</span><span class="pln">trim</span><span class="pun">(),</span><span class="pln"> currentUrl</span><span class="pun">));</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> reArrayList</span><span class="pun">;</span></code></li><li class="L9"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L2"><code class="language-java"><span class="com">     *  转化URL中的中文字符</span></code></li><li class="L3"><code class="language-java"><span class="com">     * @param url</span></code></li><li class="L4"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L5"><code class="language-java"><span class="com">     * @throws UnsupportedEncodingException </span></code></li><li class="L6"><code class="language-java"><span class="com">     */</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> encodeUrlCh</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> url</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">UnsupportedEncodingException</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">while</span><span class="pun">(</span><span class="kwd">true</span><span class="pun">){</span></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="typ">String</span><span class="pln"> s </span><span class="pun">=</span><span class="pln"> getFirstString</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> </span><span class="typ">CHRegex</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span></code></li><li class="L0"><code class="language-java"><span class="pln">            </span><span class="kwd">if</span><span class="pun">(</span><span class="typ">StringUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">s</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"><span class="pln">                </span><span class="kwd">return</span><span class="pln"> url</span><span class="pun">;</span></code></li><li class="L2"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">            url </span><span class="pun">=</span><span class="pln"> url</span><span class="pun">.</span><span class="pln">replace</span><span class="pun">(</span><span class="pln">s</span><span class="pun">,</span><span class="pln"> </span><span class="typ">URLEncoder</span><span class="pun">.</span><span class="pln">encode</span><span class="pun">(</span><span class="pln">s</span><span class="pun">,</span><span class="pln"> </span><span class="str">"utf-8"</span><span class="pun">));</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L6"><code class="language-java"><span class="pun">}</span></code></li></ol></pre>
						<div
							class="md-section-divider"></div>
					<h2 data-anchor-id="whyy" id="4-ioutils">4. IOUtils</h2>
					<p data-anchor-id="gthu"><em>可结合commons-io 工具类使用</em></p>
					<div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="a9vp" style=""><ol class="linenums"><li class="L0"><code class="language-java"><span class="com">/**</span></code></li><li class="L1"><code class="language-java"><span class="com"> * IO工具类</span></code></li><li class="L2"><code class="language-java"><span class="com"> * @author VIC</span></code></li><li class="L3"><code class="language-java"><span class="com"> *</span></code></li><li class="L4"><code class="language-java"><span class="com"> */</span></code></li><li class="L5"><code class="language-java"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">IOUtils</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="com">/**</span></code></li><li class="L8"><code class="language-java"><span class="com">     * 1 根据路径和文件名创建文件</span></code></li><li class="L9"><code class="language-java"><span class="com">     * @param path</span></code></li><li class="L0"><code class="language-java"><span class="com">     * @param name</span></code></li><li class="L1"><code class="language-java"><span class="com">     * @return</span></code></li><li class="L2"><code class="language-java"><span class="com">     */</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">File</span><span class="pln"> getFileByPathAndName</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> path</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> name</span><span class="pun">){</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="typ">File</span><span class="pln"> dir </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">File</span><span class="pun">(</span><span class="pln">path</span><span class="pun">);</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pun">(</span><span class="pln"> </span><span class="pun">!</span><span class="pln">dir</span><span class="pun">.</span><span class="pln">exists</span><span class="pun">()</span><span class="pln"> </span><span class="pun">){</span></code></li><li class="L6"><code class="language-java"><span class="pln">            dir</span><span class="pun">.</span><span class="pln">mkdirs</span><span class="pun">();</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">File</span><span class="pun">(</span><span class="pln">path</span><span class="pun">,</span><span class="pln"> name</span><span class="pun">);</span></code></li><li class="L9"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pun">}</span></code></li></ol></pre></div>

				<!--********************************-->
			</div>
		</div>
		</div>
	</body>

</html>